package com.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/loginCheck")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //如何获取数据
       String uname =  req.getParameter("username");
       String password=req.getParameter("pwd");
       //如何处理
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();

        if (uname != null && uname.length()>0 && password !=null && password.length()>0) {
//            验证
            if (uname.equals("abc") && password.equals("123")) {
                out.println(uname + ":欢迎你，恭喜你登录成功");
            } else{
                out.println("用户名或密码不正确");
            }
        } else {
            out.println("用户名或者密码为空，请重新输入");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
